#pragma once
#ifndef myWindowlet_h__
#define myWindowlet_h__

#include "./myControl.h"


#include "../adapter/skyPict.h"
#include "../adapter/skyPainter.h"
#include "../adapter/skyInput.h"
#include "../adapter/skyFile.h"
#include "../adapter/skyFont.h"
#include "../adapter/skyCanvas.h"

namespace Framework
{
//class myEventSender;
//class myMenuBar;
//class myMsgWindow;
//class myMsgBox;
	class myEvent;
	class myEventManager;
	class myResManager;
	using namespace Sky;
	
	class myWindowlet : public myControl
	{
		friend class TreeManager;
		DECL_RTTI1(myWindowlet,myControl);
	private:
		TBool m_bActived;
		NType::TRect m_DirtyRect;
		myControlManager m_CtlManager;
		myControl*   m_Focused;
	public:
		myWindowlet();
		myWindowlet(TInt id);
		virtual ~myWindowlet();
		virtual TBool Create(TInt x,TInt y,TInt w,TInt h,myResManager* resManager);
		virtual TVoid Delete();

		static TBool    doCommand(TUint command,TUint data);

		MsgStatus handlePostEvent(myEventManager* manager,Message* event);
		MsgStatus handleSendEvent(myEventManager* manager,Message* event);
		MsgStatus handleUIEvent( myEventManager* manager,Message* event );
		/*virtual TResult	onAttach(		myEventManager* manager,myEvent* event){return vUnHandled;};
		virtual TResult	onDetach(		myEventManager* manager,myEvent* event){return vUnHandled;};
		virtual TResult onPaint(		myEventManager* manager,myEvent* event){return vUnHandled;}
		virtual TResult onCreate(		myEventManager* manager,myEvent* event){return vUnHandled;}
		virtual TResult	onInput(		myEventManager* manager,myEvent* event){return vUnHandled;}
		virtual TResult	onFocusChange(	myEventManager* manager,myEvent* event){return vUnHandled;};*/
	protected:
		virtual MsgStatus	onPostEvent(	myEventManager* manager,Message* event);
		virtual MsgStatus	onSendEvent(	myEventManager* manager,Message* event);
		virtual MsgStatus	onFocusNext(	myEventManager* manager,Message* event);
		virtual MsgStatus   onFocusPrev(	myEventManager* manager,Message* event);
		virtual MsgStatus	onSizeChange(	myEventManager* manager,Message* event);
		virtual MsgStatus	onInput(		myEventManager* manager,Message* event);
		/*virtual TResult	onTimer(		myEventManager* manager,myEvent* event){return vUnHandled;};*/

		//
		NType::TVoid setActive(TBool active){m_bActived = active;}
		//
		NType::TBool isActive(){return m_bActived;}
	public:
		//images in rect is invalid,need redraw 
		NType::TBool onAreaInvalidate( NType::TRect* rect );
		//control need redraw
		NType::TBool onControlInvalidate( myControl* ctrl);
		//
		NType::TVoid Draw(Sky::Painter* painter);
		NType::TVoid Draw(Sky::Painter* painter,myControl* ctrl);
		
		
		
		myControlManager* getControlManager(){return &m_CtlManager;}
	};

	typedef RefPtr<myWindowlet> myWindowletPtr;

	class myWindowletMessage : public myCtrlMessage
	{
		DECL_RTTI1(myWindowletMessage,myCtrlMessage);
	public:
		template <typename cls>
		myWindowletMessage(MsgStatus (cls::*event)(myEventManager*,Message*),Object* sender = vNull,Object* message = vNull):myCtrlMessage(event,sender,message){}
		MsgStatus invokeHandler(myEventManager* manager,Handler* handler);
	};
	typedef RefPtr<myWindowletMessage> myWindowletMessagePtr;
}
#endif // myWindowlet_h__
